package com.utils;

import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;

/**
 * 日期：2019年3月20日
 * 公司：北京子杰宝贝科技有限公司
 * 地址：北京市朝阳区朝阳农场
 * 开发者：达选文
 * <p>
 * 主体功能：动画底层封装类
 */

public class Animation {
    private static AnimationSet mAnimaSet;
    private static Animation mAnima;

    public static Animation getAnimationSet(){
        mAnimaSet=new AnimationSet(true);

        if(mAnima==null){
            mAnima=new Animation();
        }
        return mAnima;
    }

    /**
     * 渐变动画
     * @param startAlpha
     * @param endAlpha
     */
    public Animation addAlphaAnima(float startAlpha, float endAlpha) {
        AlphaAnimation mAlphaAnima = new AlphaAnimation(startAlpha,endAlpha);
        mAnimaSet.addAnimation(mAlphaAnima);
        return mAnima;
    }

    /**
     * 旋转动画
     * @return
     */
    public Animation addRotateAnima(float startAngle, float endAngle){
        RotateAnimation mRotateAnima= new RotateAnimation(startAngle,endAngle);
        mAnimaSet.addAnimation(mRotateAnima);
        return mAnima;
    }

    /**
     * 缩放动画
     * @return
     */
    public Animation addScaleAnima(float formX, float toX, float fromY, float toY){
        ScaleAnimation mScaleAnima= new ScaleAnimation(formX, toX,fromY,toY);
        mAnimaSet.addAnimation(mScaleAnima);
        return mAnima;
    }

    /**
     * 位移动画
     * @param fromXDelta
     * @param toXDelta
     * @param fromYDelta
     * @param toYDelta
     * @return
     */
    public Animation addTranslateAnima(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta){
        TranslateAnimation mTranslate= new TranslateAnimation(fromXDelta, toXDelta,fromYDelta,toYDelta);
        mAnimaSet.addAnimation(mTranslate);
        return mAnima;
    }

    public Animation setDuration(long durating){
        mAnimaSet.setDuration(durating);
        return mAnima;
    }

    public Animation startAnimation(View view){
        view.startAnimation(mAnimaSet);
        return mAnima;
    }

    public Animation setAnimationListener(android.view.animation.Animation.AnimationListener listener ){
        mAnimaSet.setAnimationListener(listener);
        return mAnima;
    }
}
